package kjh820909.swing;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ZipcodeMain extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField zip1;
	private JTextField zip2;
	private JTextField addr;
	private JTextField etcAddr;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			ZipcodeMain dialog = new ZipcodeMain();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public ZipcodeMain() {
		setTitle("우편번호 검색기");
		setBounds(100, 100, 640, 480);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		
		JLabel zip = new JLabel("우편번호");
		zip.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		
		zip1 = new JTextField();
		zip1.setColumns(4);
		
		JLabel lines = new JLabel(" -");
		
		zip2 = new JTextField();
		zip2.setColumns(4);
		
		JButton zipBtn = new JButton("우편번호 찾기");
		zipBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ZipcodeSub z = 
						new ZipcodeSub(zip1,zip2,addr,etcAddr);
				z.setVisible(true);
			}
		});
		
		JLabel txtAddr = new JLabel("기본주소");
		txtAddr.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		
		addr = new JTextField();
		addr.setColumns(10);
		
		JLabel txtEtcaddr = new JLabel("나머지주소");
		txtEtcaddr.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		
		etcAddr = new JTextField();
		etcAddr.setColumns(10);
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(89)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(zip)
						.addComponent(txtAddr)
						.addComponent(txtEtcaddr))
					.addGap(27)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING, false)
						.addComponent(etcAddr)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addComponent(zip1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lines)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(zip2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addGap(24)
							.addComponent(zipBtn))
						.addComponent(addr))
					.addContainerGap(178, Short.MAX_VALUE))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(63)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(zip)
						.addComponent(lines)
						.addComponent(zipBtn)
						.addComponent(zip1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(zip2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(txtAddr)
						.addComponent(addr, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(txtEtcaddr)
						.addComponent(etcAddr, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(248, Short.MAX_VALUE))
		);
		contentPanel.setLayout(gl_contentPanel);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
